package modellayer;

import java.util.ArrayList;

public class ItemContainer {
	private static ItemContainer instance;
	private ArrayList<Item> items;
	
	private ItemContainer() {
		items = new ArrayList<Item>();
	}
	public static ItemContainer getInstance()
	{
		if(instance == null){
			instance = new ItemContainer();
		}
		return instance;
	}
	public ArrayList<Item> getItems() {
		return items;
	}
	
	public Item findItem(int itemID){
        Item returnItem = null;
        boolean found = false;
        int size = items.size();
        for(int i = 0;  i < size && !found;i++)
        {
            if(items.get(i).getItemID() == (itemID))
            {
            	returnItem = items.get(i);
                found = true;
            }
        }
        return returnItem;
    }
	
	public void removeItem(int itemID){
		Item tempI = findItem(itemID);
		items.remove(tempI);
	}

	public void updateItem(String type, int oldItemID, int newItemID, double price){
		Item tempI = findItem(oldItemID);
		tempI.setItemID(newItemID);
		tempI.setPrice(price);
		tempI.setType(type);
	}
	
	public void addItem(Item i){
		items.add(i);
	}
}
